<?php
/**
 * <pre>
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		    : x4you
 * COPYRIGHT	: 2009
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 * 
 * </pre>
 * 
 * Created on	: May 28, 2009
 * 
 * @author		hoadn <hoadn@rubik.com.vn>
 * @access		[public/private]
 * @package	[package name]
 *
 */

defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
RCoreImporter::cls( "mvc.AbstractController" );

class AbstractFrontController extends AbstractController {

	/**
	 * Execute a task by triggering a method in the derived class.
	 *
	 * @access	public
	 * @param	string The task to perform. If no matching task is found, the
	 * '__default' task is executed, if defined.
	 * @return	mixed|false The value returned by the called method, false in
	 * error case.
	 * 
	 */
	function execute($task, $useDefault = true) {
		$task = str_replace('.php', '', $task);
		$task = str_replace('-', '_', $task);
		parent::execute($task, $useDefault);
	}

	/**
	 * Get the capcha image protector control
	 * @return CaptchaImgProtect
	 */
	function &__getCaptchaCtrl() {
		RCoreImporter::cls('security.CaptchaImgProtect');
		$protector = new CaptchaImgProtect($_REQUEST);
		return $protector;
	}
	
	function __initJsValid($formId = null) {
		SysResponse::addJavascriptFile('libraries/js/jquery.validate.min.js');
		if ($formId) {
			$js = "
			$().ready(function() {
				// validate signup form on keyup and submit
				var validator = $('#{$formId}').validate({
					// errorLabelContainer: $('div.msg')
//					wrapper: 'span style=\"position: relative;\"',
//					errorElement: 'label',
					errorPlacement: function(error, element) {
						alert(error.text());
						element.after(error);
					}
				});
				$('#{$formId}').bind('invalid-form.validate', function() {
										$('div.msg').html('Your form contains ' + validator.numberOfInvalids() + ' errors, see details below.');
									});
			});
			";
			
			SysResponse::addJavascriptContent($js);
		}
	}
	
	/**
	 * Function for getting the html tool tip box for a form
	 *  
	 * @param $msg the text that will show in the tool tip
	 * @return string
	 */
	function _getToolTipBoxHtml($msg) {
//		$msg	= SysDBLanguage::_($msg, SysRequest::application()."_tooltip");
		$tmpUrl = SYS_CUR_TMPL_URL;
		$toolTip = "
					<div class=\"preview-tooltip floatleft\">
					   	<img src=\"{$tmpUrl}images/question.gif\" alt=\"\" border=\"0\" />
					    <table class=\"view-tooltip\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:150px;\">
					        <tr>
					            <td><img src=\"{$tmpUrl}images/top-left.gif\" alt=\"\" border=\"0\" /></td>
					                <td class=\"main-top\"></td>
					                <td><img src=\"{$tmpUrl}images/top-right.gif\" alt=\"\" border=\"0\" /></td>
					            </tr>
					            <tr>
					            <td class=\"main-left\"></td>
					            <td class=\"main\">
					                <p class=\"floatleft\">{$msg}</p>
					            </td>
					            <td class=\"main-right\"></td>
					        </tr>
					        <tr>
					            <td><img src=\"{$tmpUrl}images/bottom-left.gif\" alt=\"\" border=\"0\" /></td>
					        	<td class=\"main-bottom\"></td>
					            <td><img src=\"{$tmpUrl}images/bottom-right.gif\" alt=\"\" border=\"0\" /></td>
					        </tr>
					    </table>
					</div>
		";
		return $toolTip;
	}
}